// pages/ewm/ewm.ts
Page({

  /**
   * 页面的初始数据
   */
  data: {
    time: '',
    yem: '',
  },

  /**
   * 生命周期函数--监听页面加载
   */
  async onLoad(options) {
    let a = '7022148753276928'
    // const res = await wx.http.get(`/visitor/${decodeURIComponent(options.id)}`)
    const res = await wx.http.get(`/visitor/7022148753276928`)
    console.log(res)
    this.setData({
      obj: res.data,
      time: res.data.validTime
    })
    this.timea(this.data.time)
    let set = setInterval(() => {
      this.setData({
        time: this.data.time - 1
      })
      this.timea(this.data.time)
      if (this.data.time <= 0) clearInterval(set)
    }, 1000)
  },
  timea(totalSeconds) {
    const hours = Math.floor(totalSeconds / 3600);
    const minutes = Math.floor((totalSeconds - (hours * 3600)) / 60);
    const seconds = totalSeconds - (hours * 3600) - (minutes * 60);
    const h = String(hours).padStart(2, '0');
    const m = String(minutes).padStart(2, '0');
    const s = String(seconds).padStart(2, '0');
    this.setData({
      yem: `${h} : ${m} : ${s}`
    })
  }
})